﻿using CpsyV2Web.DataAccess;
using Longbow.Web.Mvc;
using System.Linq;

namespace CpsyV2Web.Models
{
    public class QueryPersonOptions : PaginationOption
    {
        /// <summary>
        /// 查询条件-姓名
        /// </summary>
        public string Name { get; set; }
 
        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <returns></returns>
        public QueryData<Person> RetrieveData()
        {
            var data = PersonHelper.RetrievePerson();
            if (!string.IsNullOrEmpty(Name))
            {
                data = data.Where(t => t.PersonName.Contains(Name));
            }
            var ret = new QueryData<Person>();
            ret.total = data.Count();
            switch (Sort)
            {
                case "PersonName":
                    data = Order == "asc" ? data.OrderBy(t => t.PersonName) : data.OrderByDescending(t => t.PersonName);
                    break;
                default:
                    break;
            }
            ret.rows = data.Skip(Offset).Take(Limit);
            return ret;
        }
    }
}